package com.lzq.springboot_lzq.exception;

import com.lzq.springboot_lzq.pojo.ResponseMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import org.slf4j.Logger;

@RestControllerAdvice
public class GlobalExceptionHandlerAdvice {

    Logger log = LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);

    /**
     * 处理IllegalArgumentException类型的异常。
     * 当控制器层抛出IllegalArgumentException时，该方法会被调用，
     * 并返回一个包含错误信息的ResponseEntity对象。
     */
    @ExceptionHandler({Exception.class})
    public ResponseMessage handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
        //记录日志
        log.error("统一异常：", e);
        return new ResponseMessage(e.getMessage(), null, 500);
    }

    // 其他异常处理方法...
}
